package com.xiaoxx.coin.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum ContractTypeEnum {
    // 永续合约
    PERPETUAL("PERPETUAL", "永续合约"),
    // 当月交割合约
    CURRENT_MONTH("CURRENT_MONTH", "当月交割合约"),
    // 次月交割合约
    NEXT_MONTH("NEXT_MONTH", "次月交割合约"),
    // 当季交割合约
    CURRENT_QUARTER("CURRENT_QUARTER", "当季交割合约"),
    // 次季交割合约
    NEXT_QUARTER("NEXT_QUARTER", "次季交割合约"),
    // 交割结算中合约
    PERPETUAL_DELIVERING("PERPETUAL_DELIVERING", "交割结算中合约");


    private String code;
    private String name;

    // 根据 code 获取枚举
    public static ContractTypeEnum getByCode(String code) {
        for (ContractTypeEnum type : ContractTypeEnum.values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null; // 或抛出异常
    }

    // 获取所有枚举项的字符串列表
    public static String getAllNames() {
        StringBuilder names = new StringBuilder();
        for (ContractTypeEnum type : ContractTypeEnum.values()) {
            names.append(type.getName()).append(", ");
        }
        return names.toString();
    }
}
